package org.ru.mse10.cvis.web.bean;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

import org.ru.mse10.cvis.entity.codelists.CodelistValue;
import org.ru.mse10.cvis.service.CodelistService;

/**
 * The Class CodelistBean.
 */
@SessionScoped
@ManagedBean(name = "codelistBean")
public class CodelistBean {

	/** The service. */
	@EJB
	private CodelistService service;

	/**
	 * Gets the codelist values as select items.
	 * 
	 * @param cl
	 *            the cl
	 * @param lang
	 *            the lang
	 * @return the codelist values as select items
	 */
	public List<SelectItem> getCodelistValuesAsSelectItems(String cl,
			String lang) {
		List<SelectItem> items = new ArrayList<SelectItem>();
		List<CodelistValue> languages = service.retrieveValuesForCodelist(cl);
		for (CodelistValue cv : languages) {
			items.add(new SelectItem(cv.getCode(), cv.getTranslatedValues()
					.get(lang).getValue()));
		}
		return items;
	}

}
